package com.example.sourcecodelearning.config;

import com.example.framework.common.event.OperationLogEvent;
import com.example.framework.mq.kafka.core.service.KafkaConsumerService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class KafkaConfiguration {

    @Resource
    private KafkaConsumerService<OperationLogEvent> operationLogService;

    // 在 Group 上，使用 UUID 生成其后缀。这样，启动的 Consumer 的 Group 不同，以达到广播消费的目的
    // groupId = "${mq.kafka.consumer.group}" + "-" + "#{T(java.util.UUID).randomUUID()}")
    @KafkaListener(topics = "${operation.mqTopic}")
    public void consumer(List<ConsumerRecord<?, String>> records) {
        operationLogService.consume(records);
    }

}
